package com.dxf;

import com.dxf.dao.SystemUserMapper;
import com.dxf.entity.SysUser;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;

public class MybatisMain {

    public static void main(String[] args) throws IOException {
        InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
        //创建SqlSessionFactory工厂
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = builder.build(in);

        SqlSession sqlSession = factory.openSession();

        SystemUserMapper mapper = sqlSession.getMapper(SystemUserMapper.class);
        SysUser sysUser = mapper.selectUserById(1L);
        System.out.println(sysUser);

        sqlSession.close();
        in.close();
    }
}
